/**
 * 控制页面自动滚动
 * */
export function autoScroll(page) {
  return page.evaluate(() => {
    return new Promise<void>(resolve => {
      let totalHeight = 0;
      const distance = 100;
      // 每200毫秒让页面下滑100像素的距离
      const timer = setInterval(() => {
        const scrollHeight = document.body.scrollHeight;
        window.scrollBy(0, distance);
        totalHeight += distance;
        if (totalHeight >= scrollHeight) {
          clearInterval(timer);
          resolve();
        }
      }, 200);
    });
  });
}